package cn.yj.config.web;

import cn.yj.annotation.pagehelper.PageBaseController;
import cn.yj.cgs.dba.entity.Customer;
import cn.yj.commons.utils.ServletUtils;
import cn.yj.entity.BController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 永健
 * @since 2021-04-20 15:36
 */
public class AppBaseController<T> extends BController<T> implements PageBaseController<T> {
    private static final Logger log=LoggerFactory.getLogger(AppBaseController.class);
    public String getUserCode() {
        try {
            return ((Customer) getCurrentUser()).getUserCode();
        } catch (Exception e) {
            //log.error("用户未走登陆接口，获取用户信息为空",e.getMessage());
        }
        return null;
    }

    @Override
    protected <T1> T1 getCurrentUser() {
        try {
            return (T1) ServletUtils.getRequest().getAttribute("currentUser");
        } catch (Exception e) {
            log.error("用户未走登陆接口，获取用户信息为空",e.getMessage());
        }
        return null;
    }

    protected String getOpenId() {
        return ((Customer) getCurrentUser()).getMiniOpenId();
    }

    protected String getMyInviteCode() {
        return ((Customer) getCurrentUser()).getInviteCode();
    }
}
